package com.ql.dao;

import com.ql.domain.CementMixing;
import com.ql.domain.request.ConditionQuery;
import com.ql.domain.response.OperationResult;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.List;

public interface CementMixingDao {
    @Insert("insert into cement_mixing(device_type,device_code,pile_driver_num,stake_mark,longitude,latitude,slope,start_date,pile_driver_state,phase,drill_specification,water_cement_ratio,drilling_depth,drilling_speed,electricity,cement_flux,end_date,pile_length,au_aol,au_aoc,rih_av,to_drill_av,average_aol,average_aoc,average_current,pile_time,bottom_pile_aoc,bottom_pile_aol,empty_stir_depth) values(#{device_type},#{device_code},#{pile_driver_num},#{stake_mark},#{longitude},#{latitude},#{slope},#{start_date},#{pile_driver_state},#{phase},#{drill_specification},#{water_cement_ratio},#{drilling_depth},#{drilling_speed},#{electricity},#{cement_flux},#{end_date},#{pile_length},#{au_aol},#{au_aoc},#{rih_av},#{to_drill_av},#{average_aol},#{average_aoc},#{average_current},#{pile_time},#{bottom_pile_aoc},#{bottom_pile_aol},#{empty_stir_depth})")
    int insertCementMixing(CementMixing cementMixing);

    @Insert("insert into cement_mixing(device_type,start_date) values(#{device_type},#{start_date})")
    int add(CementMixing cementMixing);

    @Select("select * from cement_mixing")
    List<CementMixing> findAll();

    @Select("select pile_driver_num from cement_mixing GROUP BY pile_driver_num")
    List<String> findPileNum();

    /**
     * 条件查询
     *
     * @param conditionQuery
     * @return
     */
    List<CementMixing> findByCriteria(ConditionQuery conditionQuery);

    @Select("select * from cement_mixing where start_date >= #{start}")
    List<CementMixing> findByStart(ConditionQuery conditionQuery);

    /**
     * 根据桩号获取最大电流
     *
     * @return
     */
    @Select("select max(electricity) FROM cement_mixing WHERE stake_mark=#{stake_mark}")
    String findMaxDl(String stake_mark);

    @Select("select max(drilling_speed) FROM cement_mixing WHERE stake_mark=#{stake_mark}")
    String findMaxSpeed(String stake_mark);

    @Select("select max(slope) FROM cement_mixing WHERE stake_mark=#{stake_mark}")
    String findMaxSlope(String stake_mark);

    /**
     * 获取总桩数
     * @param stakeMark
     * @return
     */
    @Select("SELECT COUNT(1) FROM (SELECT * FROM cement_mixing GROUP BY stake_mark) t1;")
    String findTotalPiles(String stakeMark);

    /**
     * 获取总桩长
     *
     * @return
     */
    @Select("SELECT SUM(pile_length) FROM cement_mixing")
    String findTotalPileLength();

    /**
     * 获取总浆量
     *
     * @return
     */
    @Select("SELECT SUM(au_aoc) FROM cement_mixing")
    String findSumAoc();

    /**
     * 获取总灰量
     *
     * @return
     */
    @Select("SELECT SUM(au_aol) FROM cement_mixing")
    String findSumAol();

    @Select("SELECT * FROM cement_mixing WHERE pile_length >=#{s1} and pile_length <=#{s2}")
    List<CementMixing> findTest(@Param("s1") Integer s1, @Param("s2") Integer s2);


    /**
     * 条件查询作业成效
     *
     * @param devNums
     * @param cementMixing
     * @return
     */
    List<OperationResult> findByPileDriverNum(@Param("list") ArrayList<String> devNums, @Param("cementMixing") CementMixing cementMixing);

    /**
     * 条件查询作业成效
     *
     * @param cementMixing
     * @return
     */
    List<OperationResult> findByCondition(CementMixing cementMixing);


    OperationResult findOperationTotal(@Param("list") ArrayList<String> devNums, @Param("cementMixing") CementMixing cementMixing);

}
